<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );


//Require the submenu for component
    jimport( 'joomla.application.component.model' );
    jimport('joomla.utilities.date');
    
    global $jbconfig;
        
    require_once(JPATH_COMPONENT_SITE.DS.'helper'.DS.'jahelper.php');
    require_once dirname(__FILE__).DS.'asset'.DS.'jaconstants.php';
    require_once dirname(__FILE__).DS.'asset'.DS.'japermissions.php';
    require_once dirname(__FILE__).DS.'helper'.DS.'jafunctions.class.php';    
    JPlugin::loadLanguage( 'com_user' );
    JTable::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'tables'); 
    
    require_once(dirname(__FILE__).DS.'asset'.DS.'jacache'.DS.'jacache.php');
    require_once(dirname(__FILE__).DS.'asset'.DS.'jacache'.DS.'jajob.inc.php');
    require_once dirname(__FILE__).DS.'asset'.DS.'jacaptcha'.DS.'jacapcha.php'; 
    jimport('joomla.application.component.controller');
    jimport('joomla.filesystem.file');
    
    if(!defined('JAJOBBOARD_GLOBAL_CSS')){
	    global $mainframe;
	    if(file_exists(JPATH_BASE.DS.'templates/'.$mainframe->getTemplate().'/css/ja.jobboard.css')){
	    	JHTML::stylesheet('ja.jobboard.css', 'templates/'.$mainframe->getTemplate().'/css/');
	    }
	    else{
	    	JHTML::stylesheet('ja.jobboard.css', 'components/com_jajobboard/css/');
	    }
	    JHTML::script('ja.jobboard.js', 'components/com_jajobboard/js/');
	    JHTML::script('joomla.javascript.js', 'includes/js/');
//	    JHTML::script('ja.jobboard.js.php', 'includes/js/');
	    define('JAJOBBOARD_GLOBAL_CSS', true);
    }
    if(!defined('JAJOBBOARD_MOD_FILTERJOBS_JS')){	    
		JHTML::script('ja.filterjobs.js', 'modules/mod_jafilter_jobs/ja_filter_jobs/js/');
		define('JAJOBBOARD_MOD_FILTERJOBS_JS', 1);		
    
    }
    
    component_configs();
    
    require_once dirname(__FILE__).DS.'asset'.DS.'rendfield.php'; 
    
    $controller = JRequest::getCmd('controller')?JRequest::getCmd('controller'):(JRequest::getCmd('view')?JRequest::getCmd('view'):'jajobs');
    /*Check expire job*/
    
    auto_check_jobs_expire();
    //Check and send mail for employer
    if ($jbconfig ['others']->get('sendmail_expiredjob_completed')=='done')
    	autoSendmailForEmployer();

//if (!in_array($user->usertype,$backend_usertype))
//{    

	require_once (JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'controller.php');
	$view = $controller;
	// Require specific controller if requested
	if($controller) {
		$path = JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'controllers'.DS.$controller.'.php';
		if (file_exists($path)) {
			require_once $path;
		} else {
			$controller = '';
		}
	}		
	
	// Create the controller
	$classname	= 'JobBoardController'.ucfirst($controller);
	$controller = new $classname( );
	
	$task = JRequest::getVar('task', null, 'default', 'cmd');
	

	if(!isset($jbconfig['cache'])) {		    
	    $jbconfig['cache'] = new JParameter('');
	}
	
	$cache_id = ''; 
	if($jbconfig['cache']->get('caching', true)){
	   
    	$cache = new JA_Cache($jbconfig['cache']->get('cache_base', JPATH_SITE.DS.'cache'), $jbconfig['cache']->get('cache_time', 5), $jbconfig['cache']->get('caching', true));
    	
    	/* Clean cache*/
    	$cache->clean_cache($view, $task, $frontend_clean_config);
    	
    	
    	$cache_id = $cache->_makeId();	
    	if($cache_id!=''){		
    		$oldlen = strlen(ob_get_contents());
    	}	
    	
	}	
	
	$controller->execute( $task );
	
	/* Set cache */
	
	if($jbconfig['cache']->get('caching', true) && $cache_id!='' && !$cache->_cache->get($cache_id, $view)){		
		$maincontent = substr(ob_get_contents(), $oldlen);
		if($maincontent){
			$cache->_cache->store($maincontent, $cache_id, $view);		
		}
	}
		
	// Redirect if set by the controller
	$controller->redirect();
	if(JRequest::getInt('ajax', 0)){
		exit;
	}
	echo '<br/><br/><center>';
	show_powered_by();
	echo '</center>';
?>